 

namespace JGSY.Rougamo.AOP
{
    public class UserService
    {
        [Logging]
        [Performance]
        public virtual User GetUser(int userId)
        {
            Console.WriteLine($"正在获取用户ID为 {userId} 的用户信息...");
            Thread.Sleep(500); // 模拟数据库查询延迟
            
            if (userId <= 0)
            {
                throw new ArgumentException("用户ID必须为正整数", nameof(userId));
            }
            
            return new User
            {
                Id = userId,
                Name = $"用户{userId}",
                Email = $"user{userId}@example.com"
            };
        }

        [Logging]
        [Performance]
        public virtual async Task<User> GetUserAsync(int userId, CancellationToken cancellationToken = default)
        {
            Console.WriteLine($"正在异步获取用户ID为 {userId} 的用户信息...");
            await Task.Delay(300, cancellationToken); // 模拟异步操作
            
            if (userId <= 0)
            {
                throw new ArgumentException("用户ID必须为正整数", nameof(userId));
            }
            
            return new User
            {
                Id = userId,
                Name = $"用户{userId}",
                Email = $"user{userId}@example.com"
            };
        }
    }

    public class User
    {
        public int Id { get; set; }
        public string? Name { get; set; }
        public string? Email { get; set; }
    }
}    